from poker_bot.core.models.dto.withdraw import WithdrawDTO, WithdrawWithDetailsDTO
from poker_bot.database.models import Withdraw
from poker_bot.domain.withdraw import WithdrawEntity


def convert_withdraw_entity_to_db_model(withdraw: WithdrawEntity) -> Withdraw:
    return Withdraw(
        id=withdraw.id,
        status=withdraw.status,
        user_id=withdraw.user_id,
        summ=withdraw.summ,
        payment_address=withdraw.payment_address,
        payment_method_id=withdraw.payment_method_id,
    )


def convert_db_model_to_withdraw_entity(withdraw: Withdraw) -> WithdrawEntity:
    return WithdrawEntity(
        id=withdraw.id,
        status=withdraw.status,
        user_id=withdraw.user_id,
        summ=withdraw.summ,
        payment_address=withdraw.payment_address,
        payment_method_id=withdraw.payment_method_id,
    )


def convert_db_model_to_withdraw_dto(withdraw: Withdraw) -> WithdrawDTO:
    return WithdrawDTO(
        id=withdraw.id,
        status=withdraw.status,
        user_id=withdraw.user_id,
        summ=withdraw.summ,
        payment_address=withdraw.payment_address,
        payment_method_id=withdraw.payment_method_id,
        created_at=withdraw.created_at,
    )


def convert_db_model_to_withdraw_with_details_dto(
    withdraw: Withdraw, with_currency: bool = True
) -> WithdrawWithDetailsDTO:
    currency_symbol = ""
    currency = None
    if with_currency and withdraw.payment_method:
        currency_symbol = withdraw.payment_method.currency_symbol.value
        currency = withdraw.payment_method.currency

    return WithdrawWithDetailsDTO(
        id=withdraw.id,
        status=withdraw.status,
        user_id=withdraw.user_id,
        summ=withdraw.summ,
        payment_address=withdraw.payment_address,
        payment_method_id=withdraw.payment_method_id,
        created_at=withdraw.created_at,
        currency_symbol=currency_symbol,
        currency=currency,
    )
